package com.speciality.demo.demos.web;

import com.speciality.demo.demos.dto.FloodDisasterRecVO;
import com.speciality.demo.demos.dto.IrrigationDecisionVO;
import com.speciality.demo.demos.dto.SowingRecommendationVO;
import com.speciality.demo.demos.result.Result;
import com.speciality.demo.demos.service.AgriculturalAnalysisService;
import lombok.RequiredArgsConstructor;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.format.annotation.DateTimeFormat;
import org.springframework.stereotype.Repository;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

import javax.annotation.Resource;
import java.time.LocalDate;
import java.util.List;

@RestController
@RequestMapping("/api/agri")
@RequiredArgsConstructor
public class AgriculturalAnalysisController {

    private final AgriculturalAnalysisService agriculturalAnalysisService;
    @GetMapping("/getIrrDec")
    public Result<List<IrrigationDecisionVO>> getIrrigationDecision(
           // @RequestParam("startDate") @DateTimeFormat(pattern = "yyyy-MM-dd") LocalDate startDate,
            @RequestParam("endDate") @DateTimeFormat(pattern = "yyyy-MM-dd") LocalDate endDate
    ){
        LocalDate startDate = LocalDate.of(2024,10,9);
        List<IrrigationDecisionVO> irrigationDecision = agriculturalAnalysisService.getIrrigationDecision(startDate, endDate);
        if(irrigationDecision!=null){
            return Result.ok(irrigationDecision);
        }else {
            return Result.fail(null);
        }
    }
    /*
    *
    * 选择一段时间作为输入，会从中找出合适的播种时间段
    * */
    @GetMapping("/Sow")
    public Result<List<SowingRecommendationVO>> getCornSowingRec(
            @RequestParam("startDate")@DateTimeFormat(pattern = "yyyy-MM-dd")  LocalDate startDate,
            @RequestParam("endDate")@DateTimeFormat(pattern = "yyyy-MM-dd")  LocalDate endDate) {
        List<SowingRecommendationVO> recs = agriculturalAnalysisService.getSowingRec(startDate, endDate);
        return Result.ok(recs); // 替换为项目统一响应类
    }
    /*
    * 选定一段时间作为数据集，获得那之后三天的涝灾防治建议
    *
    * */
    @GetMapping("/flood")
    private Result<List<FloodDisasterRecVO>> getFloodDisasterRec(
            @RequestParam("startDate")@DateTimeFormat(pattern = "yyyy-MM-dd")  LocalDate startDate,
            @RequestParam("endDate")@DateTimeFormat(pattern = "yyyy-MM-dd")  LocalDate endDate
    ){
        //LocalDate startDate = LocalDate.of(2025,9,9);
        //LocalDate endDate = LocalDate.of(2025,10,9);
        List<FloodDisasterRecVO> floodDisasterRec = agriculturalAnalysisService.getFloodDisasterRec(startDate, endDate);
      return Result.ok(floodDisasterRec);
    }

}
